package com.bulemobi.activity.ac_login;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import com.bulemobi.data.DataCentre;
import com.bulemobi.net.tsz.afinal.FinalHttp;
import com.bulemobi.net.tsz.afinal.annotation.view.ViewInject;
import com.bulemobi.net.tsz.afinal.http.AjaxCallBack;
import com.bulemobi.net.tsz.afinal.http.AjaxParams;
import com.bulemobi.urlCentre.UrlCentre;
import com.bulemobi.util.VerifyUtil;
import com.bulemobi.view.BaseActivity;
import com.bulemobi.view.titleView.ActionBarView;
import com.jsyh.hcb.R;

/**
 * Created by 武 on 2014/9/18 0018.
 * 忘记密码
 */
public class Ac_ForgetPassword extends BaseActivity implements View.OnClickListener {
    @ViewInject(id = R.id.actionBar)
    ActionBarView actionBarView;
    @ViewInject(id = R.id.bt_confirm)
    TextView bt_confirm;
    @ViewInject(id = R.id.ac_register_verification)
    EditText ac_register_verification;
    @ViewInject(id = R.id.getVer)
    Button getVer;
    @ViewInject(id = R.id.ac_register_userName)
    EditText ac_register_userName;
    //获取验证标示
    private final String verTip = "ver";
    //确认标示
    private final String confirmTip = "confirm";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.ac_forget_password_mian);
        findActionBar();
        initView();
    }

    private void initView() {
        bt_confirm.setOnClickListener(this);
        getVer.setOnClickListener(this);
    }

    private void findActionBar() {
        actionBarView.title.setText(getResources().getString(R.string.ac_forget_password));
    }

    private void requestHttp(String url, AjaxParams params, final String type) {
        FinalHttp http = new FinalHttp();


        http.post(url, params, new AjaxCallBack<Object>() {
            @Override
            public void onStart() {
                showProgressDialog();
                super.onStart();
            }

            @Override
            public void onSuccess(Object o) {
                closeProgressDialog();
                Log.d("OnSuccess", o.toString());
                if (type.equals(verTip)) {

                } else if (type.equals(confirmTip)) {

                }
                super.onSuccess(o);
            }

            @Override
            public void onFailure(Throwable t, int errorNo, String strMsg) {
                closeProgressDialog();
                super.onFailure(t, errorNo, strMsg);
            }
        });
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.getVer:
                AjaxParams params = new AjaxParams();
                params.put("TerminalType", UrlCentre.TerminalType);
                params.put("UserType", UrlCentre.UserType);
                params.put("ChannelId", UrlCentre.ChannelId);
                params.put("Type", DataCentre.FINDPASS_TYPE);
                params.put("CheckType", UrlCentre.CHECKTYPE_FINDPASS);
//                params.put("MsgId",ac_register_verification.getText().toString());
                params.put("MsgId", "18049213481");
                requestHttp(UrlCentre.GetSMSTokenPublic, params, DataCentre.VER);
                break;
            case R.id.bt_confirm:
//                params = new AjaxParams();
//                params.put("TerminalType", UrlCentre.TerminalType);
//                params.put("UserType",UrlCentre.UserType);
//                params.put("ChannelId",UrlCentre.ChannelId);
                //验证名字确定
                if (!VerifyUtil.isMobileNO(ac_register_userName.getText().toString())) {
                    showToastShort(getResources().getString(R.string.error_phone_number));
                    return;
                    //验证码判断
                } else if (ac_register_verification.getText().length() <= 0) {
                    showToastShort(getResources().getString(R.string.forget_password_verification_code));
                    return;
                } else {
                    openActivity(Ac_ForgetPassword_New.class);
                    bt_confirm.setBackgroundResource(R.drawable.green_shape);
                }
                break;
        }
    }
}
